/* eslint-disable */
const { resolve } = require('path');
HtmlWebpackPlugin = require('html-webpack-plugin');
WorkboxWebpackPlugin = require('workbox-webpack-plugin');

/**
 * PWA:渐进式网络开发应用程序（离线可访问）
 *  workbox-->workbox-webpack-plugin
 */

module.exports = {
    entry: './src/index.js',
    output: {
        filename: 'js/[name].[contenthash:10].js',
        path: resolve(__dirname, 'build'),
    },
    module: {
        rules: [
            {
                test: /\.less$/,
                use: [
                    'style-loader',
                    'css-loader',
                    {
                        loader: 'postcss-loader',
                        options: {
                            ident: 'postcss',
                            plugins: () => [require('postcss-preset-env')()],
                        },
                    },
                    'less-loader',
                ],
            },
        ],
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './src/index.html',
            minify: {
                collapseWhitespace: true,
                removeComments: true,
            },
        }),
        new WorkboxWebpackPlugin.GenerateSW({
            /**
             * 1.帮助servicework快速启动
             * 2.删除就得servicework
             * 生成一个servicework配置文件
             */

            clientsClaim: true,
            skipWaiting: true,
        }),
    ],
    mode: 'production',
};
